/**
 * fileName:  FruitMasterWriter.java
 * author:  huaimi
 * Company:  Cloudland Studio
 * Createdate:  2014-6-7 下午1:30:30
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-7          huaimi            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.write;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseWrite;
import org.cloudland.commercial.masterdata.store.entity.FruitEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.MasterDataEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.ArgumentRelationMapper;
import org.cloudland.jdbc.ibatis.masterdata.handler.EfficacyRelationMapper;
import org.cloudland.jdbc.ibatis.masterdata.handler.MasterDataMapper;
import org.cloudland.jdbc.ibatis.masterdata.handler.NutritionRelationMapper;
import org.cloudland.jdbc.ibatis.masterdata.handler.PartMapper;
import org.cloudland.util.Randoms;
import org.springframework.stereotype.Component;

 /**
 * 水果的仓储持久化实现类，通过数据源的写模板来对仓储中的方法进行持久化操作
 * @ClassName  FruitMasterWriter
 * @author  huaimi
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Component
public class FruitMasterWriter  implements DatabaseWrite<FruitEntity> 
{

	@Resource(name="masterDataMapper")
	private MasterDataMapper fruitMapper;
	
	@Resource(name = "partMapper")
	private PartMapper partMapper;
	
	@Resource(name = "efficacyRelationMapper")
	private EfficacyRelationMapper efficacyRelationMapper;
	
	@Resource(name="nutritionRelationMapper")
	private NutritionRelationMapper nutritionRelationMapper;
	
	@Resource(name="argumentRelationMapper")
	private ArgumentRelationMapper argumentRelationMapper;
	
	/**
	 * @param entity
	 */
	public void save(FruitEntity entity) 
	{
		entity.setFruitId(Randoms.uuid());
		
		MasterDataEntity parameter = new MasterDataEntity();
		parameter.setCountryId(entity.getCountryId());
		parameter.setDescription(entity.getDescription());
		parameter.setFruitAliasName(entity.getFruitAliasName());
		parameter.setFruitCategoryId(entity.getFruitCategoryId());
		parameter.setFruitId(entity.getFruitId());
		parameter.setFruitName(entity.getFruitName());
		parameter.setFruitPinyin(entity.getFruitPinyin());
		parameter.setRegionId(entity.getRegionId());
		parameter.setTaboo(entity.getTaboo());
		
		fruitMapper.add(parameter);
	}

	/**
	 * @param entity
	 */
	public void update(FruitEntity entity) 
	{
		MasterDataEntity parameter = new MasterDataEntity();
		parameter.setCountryId(entity.getCountryId());
		parameter.setDescription(entity.getDescription());
		parameter.setFruitAliasName(entity.getFruitAliasName());
		parameter.setFruitCategoryId(entity.getFruitCategoryId());
		parameter.setFruitId(entity.getFruitId());
		parameter.setFruitName(entity.getFruitName());
		parameter.setFruitPinyin(entity.getFruitPinyin());
		parameter.setRegionId(entity.getRegionId());
		parameter.setTaboo(entity.getTaboo());
		fruitMapper.update(parameter);
	}

	/**
	 * 按分类编号删除水果信息
	 *
	 * @param entity 封装分类编号的参数
	 */
	public void delete(FruitEntity entity)
	{
		MasterDataEntity parameter = new MasterDataEntity();
		parameter.setFruitId(entity.getFruitId());
		fruitMapper.delete(parameter);
	}
	
	/**
	 * <pre>
	 * 按水果编号删除水果信息
	 * </pre>
	 *
	 * @param fruitId   
	 */
	public void deleteByFruitId(String fruitId) {
		fruitMapper.deleteByFruitId(fruitId);
	}

}
